package com.itruth.data.dao;

import java.util.ArrayList;
import java.util.List;

import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.util.Log;

import com.itruth.data.entity.Apperception;

/**
 * 操作apperception表
 * @author yj
 *
 */
public class ApperceptionDao {

	
	public static void insert(Apperception entity) {

		SQLiteDatabase db = DbHelper.getIns().getWritableDatabase();

		db.execSQL("insert into apperception(content, time) values(?, ?)",
				new Object[] { entity.getContent(), entity.getTime() });

		db.close();
	}
	
	public static List<Apperception> queryAppes() {
		
		List<Apperception> appes = new ArrayList<Apperception> ();
		
		SQLiteDatabase db = DbHelper.getIns().getReadableDatabase();
		
		Cursor cursor = db.rawQuery("select * from apperception", null);
		
		Apperception appe = null;
		
		while (cursor.moveToNext()) {
			appe = new Apperception();
			appe.setId(cursor.getInt(0));
			appe.setContent(cursor.getString(1));
//			appe.setTime(time);
			appes.add(appe);
		}
		
		db.close();
		
		return appes;
	}
	
}
